**** Evaluation of impact on kids -- full sample including spillover population ****


* 0. Read in data 

use "${dataanalysis}\KidsReplication.dta", clear
drop if kidattrite == 1

***************** KID STATS *************************

* 1. globals 

* adjusting variable names for randcmd
rename (mangroves_0 manclimate manbiodiv manconsume mangroves_6_1_index) (y1 y2 y3 y4 y5) // knowledge
rename (env_att_2 env_att_3 env_att_5_zero env_att_7_zero  env_att_8_pos env_concern_index2z) (a1 a2 a3 a4 a5 a6) // attitudes
rename (mangroves_3 mangroves_15 mangroves_1_neg mangroves_1_nat mangroves_1_tourism) (m1 m2 m3 m4 m5) // mangrove attitudes
rename  (behavior_2_pos  behavior_3  behavior_4 behavior_6_pos behavior_index_1) (b1 b2 b3 b4 b5) // behaviors

global envknowledge  y1 y2 y3 y4 y5 
global envatt a1 a2 a3 a4 a5 a6
global manatt m1 m2 m3 m4 m5
global envbehav b1 b2 b3 b4 b5
global summarytable y5 a6 m1 b5 


set scheme tab1
xtset id_y

* 2. Preliminaries
* recoding negatives to positive for interpretation
recode m1 (0=1) (1=0)
recode m2 (0=1) (1=0)

xtset id_y

gen treattime = timesincetreatment*treatindividual*post
gen treatgender= dem_gender*treatindividual*post
gen treatage = dem_age*treatindividual*post


* 3. knowledge table
if 1{

estimates clear

foreach var in $envknowledge {
  preserve
  bysort id_y: egen bal`var' = count(`var')
  keep if bal`var' == 2
  eststo xtr_`var': xtreg `var' treatindiv post control50 control75, fe nonest vce(cluster club_id)
  eststo xtrtime1_`var': xtreg `var' treatindiv post treattime control50 control75, fe nonest vce(cluster club_id)
  eststo xtrgen1_`var': xtreg `var' treatindiv post treatgender control50 control75, fe nonest vce(cluster club_id)
  eststo xtrage1_`var': xtreg `var' treatindiv post treatage control50 control75, fe nonest vce(cluster club_id) 
  sum `var' if post == 0 
  local ymeanboys = round(r(mean),0.01)
  estadd scalar s1 `ymeanboys':  xtr_`var'
  sum `var'
  local obs = r(N) 	
  estadd scalar o1 `obs': xtr_`var'
  restore	
}
		
esttab xtr_y1 xtr_y2 xtr_y3 xtr_y4 xtr_y5 using "$tables/kidsknowledgefull.tex", replace se nonotes noobs style(tex) ///
 scalar("s1 Mean baseline"  "o1 Observations") sfmt(%12.3f %12.0f ) b(%12.3f) se(%12.3f) ///
keep(treatindiv control50 control75) nolines ///
coeflabels(treatindiv "Treated"  control50 "Spillovers, 50\%" control75 "Spillovers, 75\%") nolines collabels(none) ///
		starlevels(* 0.10 ** 0.05 *** 0.01) label nomtitles ///
		nonumbers  fragment  ///
		prehead( ) ///
		posthead(\\ \midrule \\) ///
		prefoot() ///
		postfoot()
		
}


		
* 4. Environmental attitudes table
estimates clear 

if 1{		
estimates clear

foreach var in $envatt  {
  preserve
  bysort id_y: egen bal`var' = count(`var')
  keep if bal`var' == 2
  eststo xtr_`var': xtreg `var' treatindiv post control50 control75, fe nonest vce(cluster club_id)
  eststo xtrtime1_`var': xtreg `var' treatindiv post treattime control50 control75, fe nonest vce(cluster club_id)
  eststo xtrgen1_`var': xtreg `var' treatindiv post treatgender control50 control75, fe nonest vce(cluster club_id)
  eststo xtrage1_`var': xtreg `var' treatindiv post treatage control50 control75, fe nonest vce(cluster club_id) 
  sum `var' if post == 0 
  local ymeanboys = round(r(mean),0.01)
  estadd scalar s1 `ymeanboys':  xtr_`var'
  sum `var'
  local obs = r(N) 	
  estadd scalar o1 `obs': xtr_`var'
  restore  	
}
		
esttab xtr_a1 xtr_a1 xtr_a3 xtr_a4 xtr_a5 xtr_a6  using "$tables/kidsattitudesfull.tex", replace se nonotes noobs style(tex) ///
 scalar("s1 Mean baseline"  "o1 Observations") sfmt(%12.3f %12.0f ) b(%12.3f) se(%12.3f) ///
keep(treatindiv control50 control75) nolines ///
coeflabels(treatindiv "Treated"  control50 "Spillovers, 50\%" control75 "Spillovers, 75\%") nolines collabels(none) ///
		starlevels(* 0.10 ** 0.05 *** 0.01) label nomtitles ///
		nonumbers  fragment  ///
		prehead( ) ///
		posthead(\\ \midrule \\) ///
		prefoot() ///
		postfoot()
	
}

* 5. Mangrove attitudes table
/* The reason why there are many missing variables here is that for the "mangrove preferences question"  many kids
responded that they did not have mangroves near their home
*/

if 1{		
estimates clear

foreach var in $manatt {
  preserve
  bysort id_y: egen bal`var' = count(`var')
  keep if bal`var' == 2
  eststo xtr_`var': xtreg `var' treatindiv post control50 control75, fe nonest vce(cluster club_id)
  eststo xtrtime1_`var': xtreg `var' treatindiv post treattime control50 control75, fe nonest vce(cluster club_id)
  eststo xtrgen1_`var': xtreg `var' treatindiv post treatgender control50 control75, fe nonest vce(cluster club_id)
  eststo xtrage1_`var': xtreg `var' treatindiv post treatage control50 control75, fe nonest vce(cluster club_id) 
  sum `var' if post == 0 
  local ymeanboys = round(r(mean),0.01)
  estadd scalar s1 `ymeanboys':  xtr_`var'
   sum `var'
  local obs = r(N) 	
  estadd scalar o1 `obs': xtr_`var'
  restore
}  	


		
esttab xtr_m1 xtr_m2 xtr_m3 xtr_m4 xtr_m5 using "$tables/kidsmanattitudesfull.tex", replace se nonotes noobs style(tex) ///
 scalar("s1 Mean baseline"  "o1 Observations") sfmt(%12.3f %12.0f) b(%12.3f) se(%12.3f) ///
keep(treatindiv control50 control75) nolines ///
coeflabels(treatindiv "Treated"  control50 "Spillovers, 50\%" control75 "Spillovers, 75\%") nolines collabels(none) ///
		starlevels(* 0.10 ** 0.05 *** 0.01) label nomtitles ///
		nonumbers  fragment  ///
		prehead( ) ///
		posthead(\\ \midrule \\) ///
		prefoot() ///
		postfoot()
}
		
* 6. Behaviors table

if 1{		

foreach var in $envbehav  {
  preserve
  bysort id_y: egen bal`var' = count(`var')
  keep if bal`var' == 2	
  eststo xtr_`var': xtreg `var' treatindiv post control50 control75, fe nonest vce(cluster club_id)
  eststo xtrtime1_`var': xtreg `var' treatindiv post treattime control50 control75, fe nonest vce(cluster club_id)
  eststo xtrgen1_`var': xtreg `var' treatindiv post treatgender control50 control75, fe nonest vce(cluster club_id)
  eststo xtrage1_`var': xtreg `var' treatindiv post treatage control50 control75, fe nonest vce(cluster club_id) 
  sum `var' if post == 0 & dem_gender == 0
  local ymeanboys = round(r(mean),0.01)
  estadd scalar s1 `ymeanboys':  xtr_`var'
  sum `var'
  local obs = r(N) 	
  estadd scalar o1 `obs': xtr_`var'
  restore
  	
}

		
esttab xtr_b1 xtr_b2 xtr_b3 xtr_b4 xtr_b5 using "$tables/kidsbehaviorfull.tex", replace se nonotes noobs style(tex) ///
 scalar("s1 Mean baseline"  "o1 Observations") sfmt(%12.3f %12.0f) b(%12.3f) se(%12.3f) ///
keep(treatindiv control50 control75) nolines ///
coeflabels(treatindiv "Treated"  control50 "Spillovers, 50\%" control75 "Spillovers, 75\%") nolines collabels(none) ///
		starlevels(* 0.10 ** 0.05 *** 0.01) label nomtitles ///
		nonumbers  fragment  ///
		prehead( ) ///
		posthead(\\ \midrule \\) ///
		prefoot() ///
		postfoot()

}
	
